package com.jiang.专题.数组.Q151;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/17 23:13
 */
class Solution {
    // public String reverseWords(String s) {
    //     s = s.trim();
    //     String[] temp = s.split(" ");
    //     int index = temp.length - 1;
//         StringBuilder sb = new StringBuilder();
    //     System.out.println(Arrays.toString(temp));
    //     while (index >= 0) {
    //         while (temp[index].equals("")) {
    //             index--;
    //         }
    //         sb.append(temp[index]).append(" ");
    //         index--;
    //     }
    //     return sb.deleteCharAt(sb.length() - 1).toString();
    // }
    public String reverseWords(String s) {
        s = s.trim();
        List<String> list = Arrays.asList(s.split("\\s+"));
        Collections.reverse(list);
        return String.join(" ", list);
    }
}
